using System;
using System.Collections.Generic;
using System.Text;

using Irrlicht.Scene;
using Irrlicht.Video;
using Irrlicht;
using Irrlicht.Core;

using Mud.Common.Physical;

namespace Mud.Client.WinApplication.Graphics
{

    /// <summary>
    /// Represents a model of one land square
    /// </summary>
    public class LandSquareModel : Model
    {

        public AreaLandSquare LandSquare
        {
            get { return _landSquare; }
        }
        private AreaLandSquare _landSquare;


        public LandSquareModel(IrrlichtDevice device, AreaLandSquare land)
            :base(device)
        {
            _landSquare = land;
        }

        public override void AddToScene()
        {
            IAnimatedMesh mesh = Device.SceneManager.GetMesh(@"Meshes\Square.obj");
            Vector3D position = new Vector3D(_landSquare.X, _landSquare.Y, 0);
            Vector3D rotation = new Vector3D(90, 0, 0);
            Vector3D scale = new Vector3D(1, 1, 1);
            Node = Device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1, position, rotation, scale);
            ITexture texture;
            switch (_landSquare.TerrainType)
            {
                case TerrainType.Grass:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Grass.bmp");
                    break;
                case TerrainType.Dirt:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Dirt.bmp");
                    break;
                case TerrainType.Stone:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Stone.bmp");
                    break;
                case TerrainType.Water:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Water.bmp");
                    break;
                case TerrainType.Ice:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Ice.bmp");
                    break;
                case TerrainType.Sand:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Sand.bmp");
                    break;
                case TerrainType.Void:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Void.bmp");
                    break;
                default:
                    texture = Device.VideoDriver.GetTexture(@"Textures\Void.bmp");
                    break;
            }
            Node.SetMaterialTexture(0, texture);
        }

    }
}
